package priv.bruce.servlet;

import java.io.IOException;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.alibaba.fastjson.JSON;

import priv.bruce.entry.UserInfo;
import priv.bruce.service.UserService;
import priv.bruce.util.JDBCUtil;


public class Register extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private UserService userInfo = new UserService();
	
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		
		String username=request.getParameter("name");
		String password=request.getParameter("password");
		String addr1=request.getParameter("shengfen");
		String addr2=request.getParameter("city");
		String addr=addr1+addr2;
		String mail=request.getParameter("mail");
		
		String  phone=request.getParameter("phone");
		System.out.println(phone);
		System.out.println(username);
		System.out.println(addr);
		System.out.println(mail);
		//��һ���û�
		
		try {
			UserInfo aaa=userInfo.validUserInfo(username);
			System.out.println(aaa);
			if(aaa == null) {
				int changeRows=userInfo.addUser(username, password, addr, mail, phone);
				System.out.println("受影响行数"+changeRows);
				response.getWriter().append(JSON.toJSONString(changeRows));
			}else {
				response.getWriter().append(JSON.toJSONString(-1));
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
